package com.inossem.warehousestorage_inossem.request.outStorage;

import android.content.Context;

import com.google.gson.Gson;
import com.inossem.utils.log.LogUtils;
import com.inossem.warehousestorage_inossem.bean.outStorage.OutStorageOtherOverviewBean;
import com.inossem.warehousestorage_inossem.constant.RequestConstant;
import com.inossem.warehousestorage_inossem.listener.GsonBeanListener;
import com.inossem.warehousestorage_inossem.listener.StringRequestListener;
import com.inossem.warehousestorage_inossem.manage.RequestManage;
import com.inossem.warehousestorage_inossem.model.StringResponse;
import com.inossem.warehousestorage_inossem.request.Request;

import org.json.JSONException;
import org.json.JSONObject;

/**
 * 作者：wsy on 2017/12/7 14:54
 * <p>
 * 邮箱：445979770@qq.com
 */

public class OutStorageOtherMaterielOverviewRequest extends Request {

    private static final String MATERIEL_CODE = "condition";
    //    private static final String FACTORY_CODE = "factoryCode";
    private static final String INVENTORY_ADDRESS_CODE = "location_id";
    private static final String SPECIAL_INVENYORY = "spec_stock";

    public static String request(Context context, String materielCode, String factoryCode, String inventoryAddressCode, String specialInventory, GsonBeanListener gsonBeanListener) {
        String tag;
//        Map<String, String> params = new HashMap<>();
//        params.put(MATERIEL_CODE, materielCode);
////        params.put(FACTORY_CODE, factoryCode);
//        params.put(INVENTORY_ADDRESS_CODE, inventoryAddressCode);
//        params.put(SPECIAL_INVENYORY, specialInventory);
        JSONObject jsonObject = null;
        try {
            jsonObject = new JSONObject();
            jsonObject.put(MATERIEL_CODE, materielCode);
            jsonObject.put(INVENTORY_ADDRESS_CODE, inventoryAddressCode);
            jsonObject.put(SPECIAL_INVENYORY, specialInventory);
        } catch (JSONException e) {
            LogUtils.logCatchExceptionE(context, "", e);
            e.printStackTrace();
        }
        String json = jsonObject.toString();
        String url = RequestManage.getUrl(context, RequestConstant.URL_OUT_STORAGE_OTHER_MATERIEL_OVERVIEW);
        tag = RequestManage.getHttpsPostWithLoading(context, url, json, new StringRequestListener() {
            @Override
            public void onSuccess(StringResponse stringRequestResponse) {
                Gson gson = new Gson();
                OutStorageOtherOverviewBean bean = gson.fromJson(stringRequestResponse.getResponseInfo(), OutStorageOtherOverviewBean.class);
                excuteJsonBeanNew(context, bean, gsonBeanListener);
            }
        });
        return tag;
    }
}
